﻿using NRules.Fluent;
using NRules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Himp.TaskScheduling
{
    public class RuleEngine
    {
        private readonly ISessionFactory _sessionFactory;

        public RuleEngine()
        {
            var repository = new RuleRepository();
            repository.Load(x => x.From(typeof(SampleRule).Assembly));
            _sessionFactory = repository.Compile();
        }

        public void Execute(IEnumerable<object> facts)
        {
            var session = _sessionFactory.CreateSession();
            foreach (var fact in facts)
            {
                session.Insert(fact);
            }

            session.Fire();

            //using (var session = _sessionFactory.CreateSession())
            //{
            //    foreach (var fact in facts)
            //    {
            //        session.Insert(fact);
            //    }

            //    session.Fire();
            //}
        }
    }
}
